package base2dev.web.pages.musics;

import musics.model.Album;
import musics.model.Artist;

import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
import org.apache.wicket.spring.injection.annot.SpringBean;

import base2dev.core.model.Bag;
import base2dev.web.common.MasterPage;

public class ArtistPage extends MasterPage {

	private static final long serialVersionUID = -172023293058228107L;

	@SpringBean(name = "artists")
	private Bag<Artist> artists;
	private Artist entity;

	public ArtistPage(Artist a) {
		
		super("title");
		setEntity(getArtists().get(a.getId()));
		
		add(new DataView<String>("images", new ListDataProvider<String>(a.getImages() ) ){
			 
			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(final Item<String> item) {
 				item.add(new WebMarkupContainer("photo").add(new SimpleAttributeModifier("src", item.getModelObject())));				
			}
		});
 
		

		add(new Label("bla", Integer.toString(  getEntity().getImages().size() )));
	 
		add(new Label("artist.name", getEntity().getName()));
		add(new Label("artist.nick", getEntity().getNickName()));
		add(new Label("artist.history", getEntity().getHistory()));
		add(new Label("artist.points", "" + getEntity().getPoints()));
		add(new Label("artist.albums", "" + getEntity().getAlbums().size()));
		
		
		add(new DataView<Album>("list", new ListDataProvider<Album>(getEntity().getAlbums() ) ){
			 
			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(final Item<Album> item) {
				final Album a = item.getModelObject();
				item.add(new Label("album.id"  , ""+a.getId()));				
				item.add(new Label("album.name"  , a.getName()));				
				item.add(new Link("actions")
	            {
	                @Override
	                public void onClick()
	                {
	                	 setResponsePage(new AlbumPage(a));
	                }
	            });
				
			 
			}
		});

	}

	@Override
	public void setControls() {
		//call beforeset entity
		
	}

	public void setEntity(Artist entity) {
		this.entity = entity;
	}

	public Artist getEntity() {
		return entity;
	}

	public void setArtists(Bag<Artist> artists) {
		this.artists = artists;
	}

	public Bag<Artist> getArtists() {
		return artists;
	}



}